<template>
	<view>
		<u-navbar :is-back="true" :is-fixed="true" title="政策资讯"></u-navbar>
		<view class="fixed-top bg-white" style="margin-top: 44px;">

			<view class="px-2 mt-2 pb-2 dfes">
				<u-search placeholder="请输入关键字 " height="60" border-color="#8ED0F2" search-icon-color="#8ED0F2"
					bg-color="#fff" v-model="keyword" :action-style="actionStyle" @search="searchHandler"
					@custom="searchHandler" @clear="searchHandler"></u-search>
			</view>
			<u-gap height="20" bg-color="#f7f7f7"></u-gap>
		</view>
		<view class="mt-12">
			<!-- 			<scroll-view scroll-y scroll-with-animation style="height: calc(100vh - 110px);" :show-scrollbar="false"> -->
			<view class="dfex pl-2 pr-2 py-3 border-bottom" v-for="(item, index) in policyReleaseList" :key="index"
				@click="gotoDetail(item.id)">
				<view>
					<view class="font-14 text-333333">{{item.title}}</view>
					<view class="lineHight-2 mt-3">
						<view class="font-12 text-A0A0A0">{{item.source}}</view>
						<view class="font-12 text-A0A0A0">{{item.createTime}}</view>
					</view>
				</view>

				<image style="width: 143px; height: 90px; border-radius: 5%" :src="getFullImageUrl(item.cover)">
				</image>

			</view>
			<!-- </scroll-view> -->
		</view>
	</view>
</template>

<script>
	import $H from '@/common/free-lib/request.js';
	import config from "@/common/free-lib/config.js";
	export default {
		data() {
			return {
				keyword: '',
				actionStyle: {
					color: '#8ED0F2'
				},
				pageNo: 1,
				pageSize: 10,
				policyReleaseList: []
			}
		},
		onLoad() {
			this.getPolicyReleaseList();
		},
		onReachBottom() {
			this.pageNo = this.pageNo + 1;
			this.getPolicyReleaseList();
		},
		methods: {

			getFullImageUrl(url) {
				return config.baseUrl + '/' + url;
			},
			open(path) {
				uni.navigateTo({
					url: '/pages/' + path
				})
			},
			gotoDetail(id) {
				uni.navigateTo({
					url: '/pages/tabbar/index/policyDetails?id=' + id
				})
			},
			searchHandler(){
				this.policyReleaseList = [];
				this.pageNo = 1;
				this.getPolicyReleaseList();
			},
			onPullDownRefresh() {
				this.policyReleaseList = [];
				this.pageNo = 1;
				this.getPolicyReleaseList();
				uni.stopPullDownRefresh();
			},
			getPolicyReleaseList() {
				$H.get('/basisInform/policyRelease/upper/list', {
						pageNo: this.pageNo,
						pageSize: this.pageSize,
						title:this.keyword
					}, {})
					.then(res => {
						if (res.result.records.length == 0) {
							uni.showToast({
								title: '没有更多啦！',
								icon: 'success'
							});
							return;
						}
						let resList = [];
						for (let i = 0; i < res.result.records.length; i++) {
							const item = res.result.records[i];
							resList.push({
								title: item.title,
								source: item.source,
								createTime: item.createTime,
								cover: item.cover,
								id: item.id
							});
						}
						this.policyReleaseList.push(...resList);
					})
					.catch(error => {
						console.error('请求出错', error); // 处理任何错误  
					});
			},
		}
	}
</script>

<style>
</style>